jQuery(document).ready(function () {
    selectList();
    selectSchList();
});
function queryParams(params) {
    return getQueryParams(params, "searchForm");
}
function selectList(){
    $('#projectTable').bootstrapTable("destroy");
    $('#projectTable').bootstrapTable({
        method: "post",
        url: rootPath+"/myProjectCon/ajax/getProjectList"
    });
}
function selectSchList(){
    $('#scheduleTable').bootstrapTable("destroy");
    $('#scheduleTable').bootstrapTable({
        method: "post",
        url: rootPath+"/scheduleCon/ajax/getMyScheduleList",
        showExport : true,
        exportTypes: ['excel'],//['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
        Icons:'glyphicon-export',
        exportOptions:{
            ignoreColumn: [0],  //忽略某一列的索引
            fileName: '部员进度汇报列表',  //文件名称设置
            worksheetName: 'sheet1',  //表格工作区名称
            tableName: '部员汇报列表'
        },
        exportDataType : 'all'
    });
}
function submitSch() {
    var schDescribe = $("#schDescribe").val();
    var proId = $("#proIdActive").val();
    showMode();
    $.ajax({
        url: rootPath + "/scheduleCon/ajax/addSchedule",
        data: {proId:proId,schDescribe:schDescribe},
        type: "post",
        asyc: false,
        dataType: "json",
        ContentType: "application/json; charset=utf-8",
        success: function (data) {
            closeMode();
            if('0000'==data.code){
                commonJs.alertMsg(data.msg,function () {
                    $('#myModal').modal('hide');
                    $('#projectTable').bootstrapTable("refresh");
                    $('#scheduleTable').bootstrapTable("refresh");
                });
            }else{
                layer.msg(data.msg, {icon: 2});
            }
        },
        error: function (data) {
            layer.msg(data.msg);
            closeMode();
        }
    });
}
function doAddSch() {
    var selections = $('#projectTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        $("#submitBtn").hide();
        layer.msg('请选择一行数据进行操作！', function () {
            $('#myModal').modal('hide');
            $("#submitBtn").show();
        });
        return;
    }
    if(selections[0].state !='已启动'){
        $("#submitBtn").hide();
        layer.msg('此项目非“已启动”状态，不可执行此操作！', function () {
            $('#myModal').modal('hide');
            $("#submitBtn").show();
        });
        return;
    }
    if(selections[0].has_scheduled =='已汇报'){
        $("#submitBtn").hide();
        layer.msg('此项目今日已汇报，若想重新汇报请先将今日记录撤销！', function () {
            $('#myModal').modal('hide');
            $("#submitBtn").show();
        });
        return;
    }
    var proId = selections[0].pro_id;
    $("#proIdActive").val(proId);
}
function recall() {
    var selections = $('#scheduleTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    var schId = selections[0].sch_id;
    layer.open({
        content: '确定撤销?（仅可撤销当日汇报内容）',
        btn: ['确定', "取消"],
        shade: false,
        offset: '200px',
        yes: function (index, layero) {
            $.ajax({
                type: "POST",
                url: rootPath + "/scheduleCon/ajax/recallSchedule",
                data:{schId:schId},
                dataType: "json",
                success : function(data) {
                    $('#projectTable').bootstrapTable("refresh");
                    $("#scheduleTable").bootstrapTable('refresh');//刷新表格
                    if(data.code == '0000') {
                        layer.msg(data.msg, {icon: 1});
                    }else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error:function(){
                    layer.msg("启动出错！",{icon: 2});
                }
            });
        },
        cancel: function (index) {
        }
    });
}